var loading = '<div id="loading"><img style="margin-top:180px;" src="images/main/ajax-loader4.gif"></img><div style="padding-left:12px; font-weight:bold; color:#BB7700; padding-top:10px; text-shadow:1px 1px 3px #777;">Loading...</div></div>';

var loadingPie = '<div id="loading"><img style="margin-top:180px; margin-left:110px;" src="images/main/ajax-loader4.gif"></img><div style="margin-left:110px; padding-left:12px; font-weight:bold; color:#BB7700; padding-top:10px; text-shadow:1px 1px 3px #777;">Loading...</div></div>';

google.load('visualization', '1', {packages:['corechart', 'geomap', 'table', 'orgchart', 'motionchart']});

// Visualization functions
function drawPieChart(json, id, lowercase, uppercase) {
	if (json.result.length > 0) {
	    var data = new google.visualization.DataTable();
	    data.addColumn('string', uppercase);
	    data.addColumn('number', 'Number of Records');
	
	    data.addRows(json.result.length);           
	    for (var i in json.result) {
	        data.setValue(parseInt(i, 10), 0, json.result[i][lowercase]);
	        data.setValue(parseInt(i, 10), 1, parseInt(json.result[i]['count'], 10));
	    }
	
	    var chart = new google.visualization.PieChart(document.getElementById(id));
	    chart.draw(data, {width: 800, height: 450, backgroundColor:'transparent', title: uppercase + ' versus Number of Specimen Occurrence Records', is3D: true, sliceVisibilityThreshold: 1/50000});
    }
    else {
		$('#'+id).html('<div style="margin: 100px auto 0 100px; font-weight: bold; font-size: 15px; color: red;">No specimen ocurrence records found with selected filters.</div>');
	}
}

function drawTable(json, id, lowercase, uppercase) {
	if (json.result.length > 0) { 
		var data = new google.visualization.DataTable();
	    data.addColumn('string', uppercase);
	    data.addColumn('number', 'Number of Records');
	    data.addColumn('string', 'Percentage');
	    data.addRows(json.result.length);

	   	for (var i in json.result) {
	        data.setValue(parseInt(i, 10), 0, json.result[i][lowercase]);
	        data.setValue(parseInt(i, 10), 1, parseInt(json.result[i]['count'], 10));
	        data.setValue(parseInt(i, 10), 2, json.result[i]['perc']);
	    }
	
	    var table = new google.visualization.Table(document.getElementById(id));
	    table.draw(data, null);
	}
}

function drawGeoMap(json, id) {
	if (json.result.length > 0) {
	    var data = new google.visualization.DataTable();
	    data.addColumn('string', 'Country');
	    data.addColumn('number', 'Number of Records');
	
	    data.addRows(json.result.length);	
	    for (var i in json.result) {
	        data.setValue(parseInt(i, 10), 0, json.result[i]['country']);
	        data.setValue(parseInt(i, 10), 1, parseInt(json.result[i]['count'], 10));
	    }
	
	    var geomap = new google.visualization.GeoMap(document.getElementById(id));
	    geomap.draw(data, {dataMode:'regions'});
	}
	else {
		$('#'+id).html('<div style="margin: 100px auto 0 -10px; font-weight: bold; font-size: 15px; color: red;">No specimen ocurrence records found with selected filters.</div>');
	}       
}

// Specific functions
function drawBasisOfRecord() {
    $('#chart1').html(loadingPie);
    $('#table1').html('');

    $.ajax({
        type:'POST',
        url:'index.php?r=analysis/getBasisOfRecord',
        data: {'list':jFilterList},
        dataType: "json",
        success:function(json) {
            drawPieChart(json, 'chart1', 'basisofrecord', 'Basis of Record');
            drawTable(json, 'table1', 'basisofrecord', 'Basis of Record');
        }
    });
}

function drawInstitutionCode() {
    $('#chart2').html(loadingPie);
    $('#table2').html('');

    $.ajax({
        type:'POST',
        url:'index.php?r=analysis/getInstitutionCode',
        data: {'list':jFilterList},
        dataType: "json",
        success:function(json) {
            drawPieChart(json, 'chart2', 'institutioncode', 'Institution Code');
            drawTable(json, 'table2', 'institutioncode', 'Institution Code');
        }   
    });
}

function drawCollectionCode() {
    $('#chart3').html(loadingPie);
    $('#table3').html('');

    $.ajax({
        type:'POST',
        url:'index.php?r=analysis/getCollectionCode',
        data: {'list':jFilterList},
        dataType: "json",
        success:function(json) {
            drawPieChart(json, 'chart3', 'collectioncode', 'Collection Code');
            drawTable(json, 'table3', 'collectioncode', 'Collection Code');
        }
    });
}

function drawTaxon() {    	 
    $('#infovis').html(loading);

    $.ajax({
        type:'POST',
        url:'index.php?r=analysis/getTaxon',
        data: {'list':jFilterList, 'type':'0'},
        dataType: "json",
        success:function(json) {
           	$('#infovis').html('');
           	            
            spaceTree(json.result);
        }
    });
}

function drawCountry() {
        $('#chart5').html(loading);
        $('#table5').html('');

        $.ajax({
            type:'POST',
            url:'index.php?r=analysis/getCountry',
            data: {'list':jFilterList},
            dataType: "json",
            success:function(json) {
                drawGeoMap(json, 'chart5');                      
                drawTable(json, 'table5', 'country', 'Country');
            }
    });
}

function drawTime() {
        $('#chart6').html(loading);
        $('#table6').html('');
        
        var data = new google.visualization.DataTable();
			
        $.ajax({
            type:'POST',
            url:'index.php?r=analysis/getTime',
            data: {'list':jFilterList},
            dataType: "json",
            success:function(json) {
            	if (json.records.length > 0) {
	                data.addColumn('string', 'Module');
	                data.addColumn('date', 'Date');
					data.addColumn('number', 'Number of Records');
					data.addColumn('number', 'Number of Created Records');
					data.addColumn('number', 'Number of Updated Records');
					data.addColumn('number', 'Number of Deleted Records');
					
					var count = 0;									
							        
			        for (var i in json.records) {
			        	if (json.records[i]['module'] && json.records[i]['date'] && json.records[i]['count']) {
			        		data.addRows(1); 
					        data.setValue(count, 0, json.records[i]['module']);			      
				            data.setValue(count, 1, new Date(parseInt(json.records[i]['date'].substr(0,4), 10), parseInt(json.records[i]['date'].substr(5,2), 10)-1, parseInt(json.records[i]['date'].substr(8,2), 10)));
				            data.setValue(count, 2, parseInt(parseInt(json.records[i]['count']), 10));
				            count++;
			            }
			        }
			        
			        var rows = count;
			        count = 0;
			        
			        for (var i in json.create) {
			        	if (json.create[i]['module'] && json.create[i]['date'] && json.create[i]['count']) {
			        		data.addRows(1);        		
					        data.setValue(count + rows, 0, json.create[i]['module']);			      
				            data.setValue(count + rows, 1, new Date(parseInt(json.create[i]['date'].substr(0,4), 10), parseInt(json.create[i]['date'].substr(5,2), 10)-1, parseInt(json.create[i]['date'].substr(8,2), 10)));
				            data.setValue(count + rows, 3, parseInt(parseInt(json.create[i]['count']), 10));
				            count++;
			            }
			        }
			        
			        rows += count;
			        count = 0;
			        
			        for (var i in json.update) {
			        	if (json.update[i]['module'] && json.update[i]['date'] && json.update[i]['count']) {
			        		data.addRows(1);  		
			        		data.setValue(count + rows, 0, json.update[i]['module']);			      
				            data.setValue(count + rows, 1, new Date(parseInt(json.update[i]['date'].substr(0,4), 10), parseInt(json.update[i]['date'].substr(5,2), 10)-1, parseInt(json.update[i]['date'].substr(8,2), 10)));
				            data.setValue(count + rows, 4, parseInt(parseInt(json.update[i]['count']), 10));
				            count++;
			        	}
			        }
			        
			        rows += count;
			        count = 0;
			        
			        for (var i in json.delete) {
			        	if (json.delete[i]['module'] && json.delete[i]['date'] && json.delete[i]['count']) {
			        		data.addRows(1);
					        data.setValue(count + rows, 0, json.delete[i]['module']);			      
				            data.setValue(count + rows, 1, new Date(parseInt(json.delete[i]['date'].substr(0,4), 10), parseInt(json.delete[i]['date'].substr(5,2), 10)-1, parseInt(json.delete[i]['date'].substr(8,2), 10)));
				            data.setValue(count + rows, 5, parseInt(parseInt(json.delete[i]['count']), 10));
							count++;
				        }
			        }
	
					var motionchart = new google.visualization.MotionChart(document.getElementById('chart6'));
					motionchart.draw(data, {'width': 600, 'height': 400});
				}
				else {
					$('#chart6').html('<div style="margin: 0 auto 0 -10px; font-weight: bold; font-size: 15px; color: red;">No specimen ocurrence records found with selected filters.</div>');
				}
            }
    });
}

/*
var prevData;
var prevJson;

function drawTaxon(idkingdom, idphylum, idclass, idorder, idfamily, idgenus, idsubgenus, idspecificepithet, idinfraspecificepithet) {
    $('#chart4-1').html('<img style="margin-left:auto; margin-right:auto;" src="images/main/ajax-loader4.gif"></img>');
    $('#chart4-2').html('');
    $('#table4').html('');

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Current Level');
    data.addColumn('string', 'Parent Level');

    $.ajax({
        type:'POST',
        url:'index.php?r=analysis/getTaxon',
        data: {'list':jFilterList, 'idkingdom':idkingdom, 'idphylum':idphylum, 'idclass':idclass, 'idorder':idorder, 'idfamily':idfamily, 'idgenus':idgenus, 'idsubgenus':idsubgenus, 'idspecificepithet':idspecificepithet, 'idinfraspecificepithet':idinfraspecificepithet},
        dataType: "json",
        success:function(json) {
            if (json.result[0]) {
                console.log(json.result);

                data.addRows(json.result.length);

                var prev;

                if (idkingdom && idphylum && idclass && idorder && idfamily && idgenus && idsubgenus && idspecificepithet && idinfraspecificepithet) {
                    prev = 9;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(1, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(1, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(2, 0, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</div>");
                    data.setCell(2, 1, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(3, 0, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</span>");
                    data.setCell(3, 1, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</span>");
                    data.setCell(4, 0, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");
                    data.setCell(4, 1, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</div>");
                    data.setCell(5, 0, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+")'>"+json.result[0]['genus']+"</div>");
                    data.setCell(5, 1, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");
                    data.setCell(6, 0, "<div class='taxonTitle'>Subgenus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+")'>"+json.result[0]['subgenus']+"</div>");
                    data.setCell(6, 1, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+")'>"+json.result[0]['genus']+"</div>");
                    data.setCell(7, 0, "<div class='taxonTitle'>Specific Epithet</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+","+json.result[0]['idspecificepithet']+")'>"+json.result[0]['specificepithet']+"</div>");
                    data.setCell(7, 1, "<div class='taxonTitle'>Subgenus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+")'>"+json.result[0]['subgenus']+"</div>");
                    data.setCell(8, 0, "<div class='taxonTitle'>Infraspecific Epithet</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+","+json.result[0]['idspecificepithet']+","+json.result[0]['idinfraspecificepithet']+")'>"+json.result[0]['infraspecificepithet']+"</div>");
                    data.setCell(8, 1, "<div class='taxonTitle'>Specific Epithet</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+","+json.result[0]['idspecificepithet']+")'>"+json.result[0]['specificepithet']+"</div>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Scientific Name</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+","+json.result[i]['idclass']+","+json.result[i]['idorder']+","+json.result[i]['idfamily']+","+json.result[i]['idgenus']+","+json.result[i]['idsubgenus']+","+json.result[i]['idspecificepithet']+","+json.result[i]['idinfraspecificepithet']+","+json.result[i]['idscientificname']+")'>"+json.result[i]['scientificname']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Infraspecific Epithet</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+","+json.result[0]['idspecificepithet']+","+json.result[0]['idinfraspecificepithet']+")'>"+json.result[0]['infraspecificepithet']+"</div>");                     
                    }

                    drawPieChart(json, 'chart4-2', 'scientificname', 'Scientific Name');
                    drawTable(json, 'table4', 'scientificname', 'Scientific Name');
                }
                else if (idkingdom && idphylum && idclass && idorder && idfamily && idgenus && idsubgenus && idspecificepithet) {
                    prev = 8;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(1, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(1, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(2, 0, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</div>");
                    data.setCell(2, 1, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(3, 0, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</span>");
                    data.setCell(3, 1, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</span>");
                    data.setCell(4, 0, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");
                    data.setCell(4, 1, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</div>");
                    data.setCell(5, 0, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+")'>"+json.result[0]['genus']+"</div>");
                    data.setCell(5, 1, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");
                    data.setCell(6, 0, "<div class='taxonTitle'>Subgenus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+")'>"+json.result[0]['subgenus']+"</div>");
                    data.setCell(6, 1, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+")'>"+json.result[0]['genus']+"</div>");
                    data.setCell(7, 0, "<div class='taxonTitle'>Specific Epithet</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+","+json.result[0]['idspecificepithet']+")'>"+json.result[0]['specificepithet']+"</div>");
                    data.setCell(7, 1, "<div class='taxonTitle'>Subgenus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+")'>"+json.result[0]['subgenus']+"</div>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Infraspecific Epithet</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+","+json.result[i]['idclass']+","+json.result[i]['idorder']+","+json.result[i]['idfamily']+","+json.result[i]['idgenus']+","+json.result[i]['idsubgenus']+","+json.result[i]['idspecificepithet']+","+json.result[i]['idinfraspecificepithet']+")'>"+json.result[i]['infraspecificepithet']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Specific Epithet</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+","+json.result[0]['idspecificepithet']+")'>"+json.result[0]['specificepithet']+"</div>");                     
                    }

                    drawPieChart(json, 'chart4-2', 'infraspecificepithet', 'Infraspecific Epithet');
                    drawTable(json, 'table4', 'infraspecificepithet', 'Infraspecific Epithet');
                }
                else if (idkingdom && idphylum && idclass && idorder && idfamily && idgenus && idsubgenus) {
                    prev = 7;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(1, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(1, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(2, 0, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</div>");
                    data.setCell(2, 1, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(3, 0, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</span>");
                    data.setCell(3, 1, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</span>");
                    data.setCell(4, 0, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");
                    data.setCell(4, 1, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</div>");
                    data.setCell(5, 0, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+")'>"+json.result[0]['genus']+"</div>");
                    data.setCell(5, 1, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");
                    data.setCell(6, 0, "<div class='taxonTitle'>Subgenus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+")'>"+json.result[0]['subgenus']+"</div>");
                    data.setCell(6, 1, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+")'>"+json.result[0]['genus']+"</div>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Specific Epithet</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+","+json.result[i]['idclass']+","+json.result[i]['idorder']+","+json.result[i]['idfamily']+","+json.result[i]['idgenus']+","+json.result[i]['idsubgenus']+","+json.result[i]['idspecificepithet']+")'>"+json.result[i]['specificepithet']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Subgenus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+","+json.result[0]['idsubgenus']+")'>"+json.result[0]['subgenus']+"</div>");                     
                    }

                    drawPieChart(json, 'chart4-2', 'specificepithet', 'Specific Epithet');
                    drawTable(json, 'table4', 'specificepithet', 'Specific Epithet');
                }
                else if (idkingdom && idphylum && idclass && idorder && idfamily && idgenus) {
                    prev = 6;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(1, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(1, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(2, 0, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</div>");
                    data.setCell(2, 1, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(3, 0, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</span>");
                    data.setCell(3, 1, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</span>");
                    data.setCell(4, 0, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");
                    data.setCell(4, 1, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</div>");
                    data.setCell(5, 0, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+")'>"+json.result[0]['genus']+"</div>");
                    data.setCell(5, 1, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Subgenus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+","+json.result[i]['idclass']+","+json.result[i]['idorder']+","+json.result[i]['idfamily']+","+json.result[i]['idgenus']+","+json.result[i]['idsubgenus']+")'>"+json.result[i]['subgenus']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+","+json.result[0]['idgenus']+")'>"+json.result[0]['genus']+"</div>");                     
                    }

                    drawPieChart(json, 'chart4-2', 'subgenus', 'Subgenus');
                    drawTable(json, 'table4', 'subgenus', 'Subgenus');
                }
                else if (idkingdom && idphylum && idclass && idorder && idfamily) {
                    prev = 5;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(1, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(1, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(2, 0, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</div>");
                    data.setCell(2, 1, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(3, 0, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</span>");
                    data.setCell(3, 1, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</span>");
                    data.setCell(4, 0, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");
                    data.setCell(4, 1, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</div>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Genus</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+","+json.result[i]['idclass']+","+json.result[i]['idorder']+","+json.result[i]['idfamily']+","+json.result[i]['idgenus']+")'>"+json.result[i]['genus']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+","+json.result[0]['idfamily']+")'>"+json.result[0]['family']+"</div>");                      
                    }

                    drawPieChart(json, 'chart4-2', 'genus', 'Genus');
                    drawTable(json, 'table4', 'genus', 'Genus');
                }
                else if (idkingdom && idphylum && idclass && idorder) {
                    prev = 4;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(1, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(1, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(2, 0, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</div>");
                    data.setCell(2, 1, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(3, 0, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</span>");
                    data.setCell(3, 1, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</span>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Family</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+","+json.result[i]['idclass']+","+json.result[i]['idorder']+","+json.result[i]['idfamily']+")'>"+json.result[i]['family']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+","+json.result[0]['idorder']+")'>"+json.result[0]['order']+"</div>");                      
                    }

                    drawPieChart(json, 'chart4-2', 'family', 'Family');
                    drawTable(json, 'table4', 'family', 'Family');
                }
                else if (idkingdom && idphylum && idclass) {
                    prev = 3;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(1, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(1, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(2, 0, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</div>");
                    data.setCell(2, 1, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Order</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+","+json.result[i]['idclass']+","+json.result[i]['idorder']+")'>"+json.result[i]['order']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+","+json.result[0]['idclass']+")'>"+json.result[0]['class']+"</div>");                      
                    }

                    drawPieChart(json, 'chart4-2', 'order', 'Order');
                    drawTable(json, 'table4', 'order', 'Order');
                }
                else if (idkingdom && idphylum) {
                    prev = 2;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");
                    data.setCell(1, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");
                    data.setCell(1, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Class</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+","+json.result[i]['idclass']+")'>"+json.result[i]['class']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+","+json.result[0]['idphylum']+")'>"+json.result[0]['phylum']+"</div>");                      
                    }

                    drawPieChart(json, 'chart4-2', 'class', 'Class');
                    drawTable(json, 'table4', 'class', 'Class');
                }
                else if (idkingdom) {
                    prev = 1;
                    data.addRows(prev);
                    data.setCell(0, 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[0]['idkingdom']+")'>"+json.result[0]['kingdom']+"</div>");

                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10)+prev, 0, "<div class='taxonTitle'>Phylum</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+","+json.result[i]['idphylum']+")'>"+json.result[i]['phylum']+" ("+json.result[i]['count']+") </div>");
                        data.setCell(parseInt(i, 10)+prev, 1, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+")'>"+json.result[i]['kingdom']+"</div>");                      
                    }

                    drawPieChart(json, 'chart4-2', 'phylum', 'Phylum');
                    drawTable(json, 'table4', 'phylum', 'Phylum');
                }
                else {
                    for (var i in json.result) {
                        data.setCell(parseInt(i, 10), 0, "<div class='taxonTitle'>Kingdom</div><div class='taxonText' onclick='javascript:drawTaxon("+json.result[i]['idkingdom']+")'>"+json.result[i]['kingdom']+" ("+json.result[i]['count']+") </div>");
                    }

                    drawPieChart(json, 'chart4-2', 'kingdom', 'Kingdom');
                    drawTable(json, 'table4', 'kingdom', 'Kingdom');
                }

                new google.visualization.TreeChart(document.getElementById('chart4-1')).
                draw(data, {allowHtml: true});

                $("#chart4-1").overscroll({wheelDirection:'horizontal'});

                prevData = data;
                prevJson = json;
            }
            else {
                $('#Notification').jnotifyAddMessage({
                    text: "<div style='margin-left:40px; margin-bottom:10px; margin-top:10px;'>The selected taxon level has no children levels.</div>",
                    permanent: false,
                    disappearTime: 5000,
                    type: 'error'
                });
                
                new google.visualization.OrgChart(document.getElementById('chart4-1')).
                draw(prevData, {allowHtml: true, size:'large'});

                $("#chart4-1").overscroll({wheelDirection:'horizontal'});
                
                if (idkingdom && idphylum && idclass && idorder && idfamily && idgenus && idsubgenus && idspecificepithet && idinfraspecificepithet) {
                    drawPieChart(prevJson, 'chart4-2', 'infraspecificepithet', 'Infraspecific Epithet');
                    drawTable(prevJson, 'table4', 'infraspecificepithet', 'Infraspecific Epithet');
                }
                else if (idkingdom && idphylum && idclass && idorder && idfamily && idgenus && idsubgenus && idspecificepithet) {
                    drawPieChart(prevJson, 'chart4-2', 'specificepithet', 'Specific Epithet');
                    drawTable(prevJson, 'table4', 'specificepithet', 'Specific Epithet');
                }
                else if (idkingdom && idphylum && idclass && idorder && idfamily && idgenus && idsubgenus) {
                    drawPieChart(prevJson, 'chart4-2', 'subgenus', 'Subgenus');
                    drawTable(prevJson, 'table4', 'subgenus', 'Subgenus');
                }
                else if (idkingdom && idphylum && idclass && idorder && idfamily && idgenus) {
                    drawPieChart(prevJson, 'chart4-2', 'genus', 'Genus');
                    drawTable(prevJson, 'table4', 'genus', 'Genus');
                }
                else if (idkingdom && idphylum && idclass && idorder && idfamily) {
                    drawPieChart(prevJson, 'chart4-2', 'family', 'Family');
                    drawTable(prevJson, 'table4', 'family', 'Family');
                }
                else if (idkingdom && idphylum && idclass && idorder) {
                    drawPieChart(prevJson, 'chart4-2', 'order', 'Order');
                    drawTable(prevJson, 'table4', 'order', 'Order');
                }
                else if (idkingdom && idphylum && idclass) {
                    drawPieChart(prevJson, 'chart4-2', 'class', 'Class');
                    drawTable(prevJson, 'table4', 'class', 'Class');
                }
                else if (idkingdom && idphylum) {
                    drawPieChart(prevJson, 'chart4-2', 'phylum', 'Phylum');
                    drawTable(prevJson, 'table4', 'phylum', 'Phylum');
                }
                else if (idkingdom) {
                    drawPieChart(prevJson, 'chart4-2', 'kingdom', 'Kingdom');
                    drawTable(prevJson, 'table4', 'kingdom', 'Kingdom');
                }
            }
        }
    });
}*/
